<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link href="/ajax/libs/iCheck/custom.css" th:href="@{/ajax/libs/iCheck/custom.css}" rel="stylesheet"/>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-menu-add">
        <input id="treeId" name="parentId" type="hidden" th:value="${location.locationId}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label ">upOneLevelContainer：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" onclick="selectMenuTree()" id="treeName" readonly="true"
                       th:value="${location.locationName}"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">containerType：</label>
            <div class="col-sm-8">
                <label class="checkbox-inline i-checks"> <input type="radio" name="locationType" class="locationType" value="M"/> goodsShelf </label>
                <label class="checkbox-inline i-checks"> <input type="radio" name="locationType" class="locationType" value="C"/> grid </label>
                <label class="checkbox-inline i-checks"> <input type="radio" name="locationType" class="locationType" value="F"/> cargoBox </label>
                <label class="checkbox-inline i-checks"> <input type="radio" name="locationType" class="locationType" value="H"/> cargo </label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">containerName：</label>
            <div class="col-sm-8">
                <input class="form-control" th:value="${location.locationName} + '-'" type="text" name="locationName"
                       id="locationName">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">showSort：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" id="orderNum" name="orderNum">
            </div>
        </div>
        <!--<div class="form-group">
            <label class="col-sm-3 control-label">图标：</label>
            <div class="col-sm-8">
                <input id="icon" name="icon" class="form-control" type="text" placeholder="选择图标">
                <div class="ms-parent" style="width: 100%;">
                    <div class="icon-drop animated flipInX" style="display: none;max-height:200px;overflow-y:auto">
                        <div data-th-include="system/menu/icon"></div>
                    </div>
                </div>
            </div>
        </div>-->
        <!--	<div class="form-group">
                <label class="col-sm-3 control-label">菜单状态：</label>
                <div class="col-sm-8" th:with="type=${@dict.getType('sys_show_hide')}">
                    <div th:each="dict : ${type}" th:class="${dict['cssClass']}">
                        <input type="radio" th:id="${dict['dictCode']}" name="visible" th:value="${dict['dictValue']}" th:checked="${dict['isDefault'] == 'Y' ? true : false}">
                        <label th:for="${dict['dictCode']}" th:text="${dict['dictLabel']}"></label>
                    </div>
                </div>
            </div>-->
        <div class="form-group">
            <div class="form-control-static col-sm-offset-9">
                <button type="submit" class="btn btn-primary">submit</button>
                <button onclick="$.modal.close()" class="btn btn-danger" type="button">close</button>
            </div>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<script th:src="@{/ajax/libs/iCheck/icheck.min.js}"></script>
<script>
    var prefix = ctx + "module/location"
    $("#form-menu-add").validate({
        rules: {
            locationName: {
                required: true,
                remote: {
                    url: prefix + "/checkLocationNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "locationName": function () {
                            return $.trim($("#locationName").val());
                        }
                    },
                    dataFilter: function (data, type) {
                        if (data == "0") return true;
                        else return false;
                    }
                }
            },
            /*orderNum:{
                required:true,
                digits:true
            },*/
        },
        messages: {
            "menuName": {
                remote: "Shelf name already exists"
            }
        },
        submitHandler: function (form) {
           /* $.operate.save(prefix + "/add", $('#form-menu-add').serialize());*/
           add()
        }
    });


    function add() {
        var parentId = $("#treeId").val();
        var locationType = $("input[name='locationType']:checked").val();
        var locationName = $("#locationName").val();
        var orderNum = $("#orderNum").val();
        $.ajax({
            cache : true,
            type : "POST",
            url : ctx + "module/location/add",
            data : {
                "parentId": parentId,
                "locationType": locationType,
                "locationName": locationName,
                "orderNum": orderNum,
            },
            async : false,
            error : function(request) {
                $.modal.alertError("system error");
            },
            success : function(data) {
                window.parent.$("#fladata").val(data.join(","))
                setTimeout(function () {
                    $.modal.close()
                    parent.$.treeTable.refresh();
                }, 50)
            }
        });
    }

    $(function () {
        $("input[name='icon']").focus(function () {
            $(".icon-drop").show();
        });
        $("#form-menu-add").click(function (event) {
            var obj = event.srcElement || event.target;
            if (!$(obj).is("input[name='icon']")) {
                $(".icon-drop").hide();
            }
        });
        $(".icon-drop").find(".ico-list i").on("click", function () {
            $('#icon').val($(this).attr('class'));
        });
        $('input').on('ifChecked', function (event) {
            var menuType = $(event.target).val();
            if (menuType == "M") {
                $("#url").parents(".form-group").hide();
                $("#perms").parents(".form-group").hide();
                $("#icon").parents(".form-group").show();
            } else if (menuType == "C") {
                $("#url").parents(".form-group").show();
                $("#perms").parents(".form-group").show();
                $("#icon").parents(".form-group").hide();
            } else if (menuType == "F") {
                $("#url").parents(".form-group").hide();
                $("#perms").parents(".form-group").show();
                $("#icon").parents(".form-group").hide();
            }
        });
    });

    /*菜单管理-新增-选择菜单树*/
    function selectMenuTree () {
        var menuId = $("#treeId").val();
        if (menuId > 0) {
            var url = prefix + "/selectMenuTree/" + menuId;
            $.modal.open("选择菜单", url, '380', '380');
        }
        else {
            var url = prefix + "/selectMenuTree/1";
            $.modal.open("选择菜单", url, '380', '380');
        }
    }

    /*locationName失去焦点后 检查最后的是不是数字 如果是数字 则自动填写序号*/
    $('#locationName').blur(function () {
        var temorderNums = $('#locationName').val().split("-");
        var re = /^[0-999]+.?[0-999]*/;//判断字符串是否为数字//判断正整数/[1−9]+[0−9]∗]∗/
        var tem = temorderNums[temorderNums.length - 1]

        if (!re.test(tem)) {
            tem = 0
        }
        $("#orderNum").val(tem)
    })
</script>
</body>
</html>
